﻿<?php
function b(){ print '<br/>';}
require_once('konfiguration.html');
$files=array("german_portuguese"=>"deutsch portugiesisch woerterbuch2.txt");
foreach ($files as $key=> $value)
{
   $lines=file($value);
   print "$key";
   foreach($lines as $line)
   { 
   print $last_line; b(); print $line; b(); 
     preg_match_all('/^(.*?)\?(.*)/',$last_line,$matches_last,PREG_PATTERN_ORDER);
	 preg_match_all('/^(.*?)\?(.*)/',$line,$matches_line,PREG_PATTERN_ORDER);
	 print_r ($matches_last);
	 if ($matches_last[2]) 
	 {
	    if (($matches_line[2]))	eval_insert($last_line,$key);
		else eval_insert($last_line.$line,$key);
	 
	 }
   $last_line=$line;	      
   }
}

function find_article($infos)
	  {
	     preg_match_all('/^(.*?)\[(.*)\]/',$infos,$matches_article,PREG_PATTERN_ORDER);
		 if ($matches_article[2])
		     {$word=$matches_article[1][0];$article=$matches_article[2][0];}
		 else 
             {$word= $infos;$article="";}      		 
		 return array($word,$article);
	  
	  }
function eval_insert($current_line,$key)
	{
	  
print $current_line; b();
	  preg_match_all('/^(.*?)\?(.*)/s',$current_line,$matches_current,PREG_PATTERN_ORDER); 
	  $pre_word=$matches_current[1][0];
	  print $matches_current[2][0];b();
	  
	  $pre_translations=preg_split('/[,;]/',$matches_current[2][0]);
	  print_r ($pre_translations);b();
print $pre_word;b(); 
	  $arr=find_article($pre_word); $word=$arr[0]; $article=$arr[1];
print $word; b(); print $article; b();
	  foreach ($pre_translations as $pre_translation)
	  {
	     $arr=find_article($pre_translation); $translation=$arr[0]; $article_translation=$arr[1];
	     $translation=trim($translation);
		 print $translation; b(); print $article_translation; b();
         mysql_query("INSERT INTO alltranslations2 (language_combo, word, translation, article,article_translation) VALUES ('$key','$word',
        '$translation','$article','$article_translation')");
		 set_time_limit(10);
	  
	  }
	  
	}
?>